﻿using System.Data.Entity;
using System.Collections.Generic;
using Mabalacat.CPS.DataAccess.DataObjects;
using System;

namespace Mabalacat.CPS.DataAccess.Context
{

#if DEBUG    
    public class PayrollDatabaseInitializer : DropCreateDatabaseIfModelChanges<PayrollDataContext>
#else
    public class PayrollDatabaseInitializer : CreateDatabaseIfNotExists<PayrollDataContext> 
#endif
    {        
        protected override void Seed(PayrollDataContext context)
        {
            #region  Users            
            var user = new User
            {
                UserName = "admin",
                Password = "1234",
                DateAdded = DateTime.Now
            };
            user.Roles.Add(new Role { RoleName = "administrator" });
            context.Users.Add(user);

            #endregion


            //PhilHealtTable
            var philHealthItems = new List<PhilHealthTable>();
            double start = 4000;
            double incrementer = 100;
            for (int i = 1; i <= 27; i++)
            {
                philHealthItems.Add(
                    new PhilHealthTable { StartRange = start, EndRange = i < 27 ? (start + 999.99) : 0, Base = start}
                );
                start = start + 1000;
                incrementer = incrementer + 25;
            }
            philHealthItems.ForEach(x => context.PhilHealthTable.Add(x));
            context.SaveChanges();
        }

    }
}
